import request from "@/utils/request";
import * as Types from "@/api/file/types";

/**
 * 根据文件ID生成完整的下载URL
 * @param {string} fileId - 文件ID
 * @returns {string} 完整的下载URL
 */
export function getDownloadUrl(fileId: string) {
    if (!fileId) return '';
    const baseUrl = import.meta.env.VITE_SERVE + import.meta.env.VITE_APP_BASE_API;
    return `${baseUrl}/file/download?fileId=${fileId}`;
}

/**
 * 上传文件
 */
export async function upload(file: File, businessType: Types.BusinessType): Promise<Types.FileUploadResultResp> {
    const formData = new FormData()
    formData.append('file', file)
    formData.append('businessType', businessType)
    return request.post('/file/upload', formData, {
        headers: { 'Content-Type': 'multipart/form-data' }
    })
}
